<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ConfirmCartOrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $img = $this->productSku->image;
        return [
            'product_id'    => $this->product->id,
            'type'          => $this->product->type,
            'sku_id'        => $this->productSku->id,
            'total'         => $this->total,
            'amount'        => $this->amount,
            'price'         => $this->productSku->price,
            'spec_sku_name' => $this->productSku->spec_sku_name,
            'title'         => $this->product->title,
            'image'         => empty($img) ? $this->product->image : $img,
        ];
    }
}
